class Sales::RegistersController < ApplicationController
  layout 'sessions'
  before_action :set_store_id
  def new
  end

  def create
    @customer = StoreCustomer.new(customer_params)
    if @customer.save
      redirect_to new_sales_session_path(store_id: @store_id)
    else
      redirect_to new_sales_register_path(store_id: @store_id), notice: @customer.errors.full_messages.first
    end
  end

  private
  def customer_params
    params.permit(:login_name, :password, :password_confirmation, :company_name, :name, :company_address, :phone_number)
  end

  def set_store_id
    @store_id ||= params[:store_id]
  end
end
